package com.dpwgc.provider.service;

import com.dpwgc.provider.mapper.HunterMapper;
import com.dpwgc.provider.model.Hunter;
import com.dpwgc.provider.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HunterService {

    @Autowired
    HunterMapper hunterMapper;
    /**
     * 创建猎人账号
     * @param hunter
     * @return
     */
    public ResultUtil<Object> createHunterService(Hunter hunter){
        ResultUtil<Object> resultUtil = new ResultUtil<>();

        try {
            int res = hunterMapper.createHunter(hunter);
            resultUtil.setCode(200);
            resultUtil.setMsg("猎人认证成功");
            resultUtil.setData(res);
            return resultUtil;
        }catch (Exception e){
            resultUtil.setCode(100);
            resultUtil.setMsg("猎人认证失败");
            resultUtil.setData(e);
            return resultUtil;
        }
    }

    /**
     * 取消猎人资质
     * @param hunterUuid
     * @return
     */
    public ResultUtil<Object> deleHunterService(String hunterUuid){
        ResultUtil<Object> resultUtil = new ResultUtil<>();

        try {
            int res = hunterMapper.deleHunter(hunterUuid);
            resultUtil.setCode(200);
            resultUtil.setMsg("取消猎人认证成功");
            resultUtil.setData(res);
            return resultUtil;
        }catch (Exception e){
            resultUtil.setCode(100);
            resultUtil.setMsg("取消猎人认证失败");
            resultUtil.setData(e);
            return resultUtil;
        }
    }

    /**
     * 获取猎人信息
     * @param hunterUuid
     * @return
     */
    public ResultUtil<Object> getHunterService(String hunterUuid){
        ResultUtil<Object> resultUtil = new ResultUtil<>();

        try {
            Hunter hunter = hunterMapper.getHunter(hunterUuid);
            resultUtil.setCode(200);
            resultUtil.setMsg("获取猎人成功");
            resultUtil.setData(hunter);
            return resultUtil;
        }catch (Exception e){
            resultUtil.setCode(100);
            resultUtil.setMsg("获取猎人失败");
            resultUtil.setData(e);
            return resultUtil;
        }
    }

    /**
     * 根据status返回猎人列表
     * @param hunterStatus
     * @return
     */
    public ResultUtil<Object> listHunterService(int hunterStatus,Integer startPage,Integer endPage){
        ResultUtil<Object> resultUtil = new ResultUtil<>();

        try {
            List<Hunter> hunters = hunterMapper.listHunter(hunterStatus,startPage,endPage);
            resultUtil.setCode(200);
            resultUtil.setMsg("操作成功");
            resultUtil.setData(hunters);
            return resultUtil;
        }catch (Exception e){
            resultUtil.setCode(100);
            resultUtil.setMsg("操作失败");
            resultUtil.setData(e);
            return resultUtil;
        }
    }

    /**
     * 猎人完成订单后个人订单总数+1
     * @param hunterUuid
     * @return
     */
    public ResultUtil<Object> hunterDnNumAddService(String hunterUuid){
        ResultUtil<Object> resultUtil = new ResultUtil<>();

        try {
            int res = hunterMapper.hunterDnNumAdd(hunterUuid);
            resultUtil.setCode(200);
            resultUtil.setMsg("操作成功");
            resultUtil.setData(res);
            return resultUtil;
        }catch (Exception e){
            resultUtil.setCode(100);
            resultUtil.setMsg("操作失败");
            resultUtil.setData(e);
            return resultUtil;
        }
    }

    /**
     * 猎人完成订单后个人订单总分增加
     * @param
     * @return
     */
    public ResultUtil<Object> hunterTotalScoreAddService(String hunterUuid,int hunterScore){
        ResultUtil<Object> resultUtil = new ResultUtil<>();

        try {
            int res = hunterMapper.hunterTotalScoreAdd(hunterUuid,hunterScore);
            resultUtil.setCode(200);
            resultUtil.setMsg("操作成功");
            resultUtil.setData(res);
            return resultUtil;
        }catch (Exception e){
            resultUtil.setCode(100);
            resultUtil.setMsg("操作失败");
            resultUtil.setData(e);
            return resultUtil;
        }
    }

    /**
     * 猎人钱包存款增加
     * @param
     * @return
     */
    public ResultUtil<Object> hunterWalletAddService(String hunterUuid,double wallet){
        ResultUtil<Object> resultUtil = new ResultUtil<>();

        try {
            int res = hunterMapper.hunterWalletAdd(hunterUuid,wallet);
            resultUtil.setCode(200);
            resultUtil.setMsg("操作成功");
            resultUtil.setData(res);
            return resultUtil;
        }catch (Exception e){
            resultUtil.setCode(100);
            resultUtil.setMsg("操作失败");
            resultUtil.setData(e);
            return resultUtil;
        }
    }

    /**
     * 猎人钱包存款减少
     * @param
     * @return
     */
    public ResultUtil<Object> hunterWalletReduceService(String hunterUuid,double wallet){
        ResultUtil<Object> resultUtil = new ResultUtil<>();

        try {
            int res = hunterMapper.hunterWalletReduce(hunterUuid,wallet);
            resultUtil.setCode(200);
            resultUtil.setMsg("操作成功");
            resultUtil.setData(res);
            return resultUtil;
        }catch (Exception e){
            resultUtil.setCode(100);
            resultUtil.setMsg("操作失败");
            resultUtil.setData(e);
            return resultUtil;
        }
    }
}
